package cn.bluethink.eguan.core.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.bluethink.eguan.core.security.Token;
import cn.bluethink.eguan.core.service.EgTaskService;
import cn.bluethink.eguan.filter.OtypeFilter;
import cn.bluethink.eguan.model.core.EgTask;
import cn.bluethink.eguan.model.core.EgUser;
import cn.bluethink.eguan.result.PageInfo;
import cn.bluethink.eguan.result.ResponseMessage;
import cn.bluethink.eguan.result.ResponseResult;

@CrossOrigin
@RestController
@RequestMapping("/eguan/v1.0/task")
public class EgTaskController {

	@Autowired
	private EgTaskService taskService;
	
    /**
     * 根据任务的ID(获取发布地)获取用户列表(门派成员/驿馆伙计)
     * 
     * @param filter
     * @return
     * @throws Exception
     */
    @Token
    @PostMapping("/users")
    public ResponseResult<PageInfo<EgUser>> users(@RequestBody OtypeFilter filter) throws Exception {
    	Long id = filter.getId();
    	if(id == null || id == 0) return new ResponseResult<>(ResponseMessage.NOTNULL_ID);
        EgTask task = taskService.detail(id, filter.getOtype());
        if (task == null) {
            return new ResponseResult<>(ResponseMessage.NOT_FOUND);
        }
        return new ResponseResult<>(ResponseMessage.OK, taskService.users(task, filter));
    }
}
